package com.wjy.icu.service.impl;

import com.wjy.icu.domain.Equipment;
import com.wjy.icu.domain.EquipmentExample;
import com.wjy.icu.domain.EquipmentFunc;
import com.wjy.icu.domain.vo.BluetoothVo;
import com.wjy.icu.domain.vo.EquipmentDto;
import com.wjy.icu.mapper.EquipmentFuncMapper;
import com.wjy.icu.mapper.EquipmentMapper;
import com.wjy.icu.service.IBluetoochService;
import com.wjy.icu.service.IEquipmentService;
import com.wjy.icu.service.IMqttService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @author: wangjunyong
 * @date: 2021/10/27 15:13
 */
@Service
public class EquipmentServiceImpl implements IEquipmentService {

    @Resource
    EquipmentMapper equipmentMapper;
    @Resource
    EquipmentFuncMapper equipmentFuncMapper;
    @Autowired
    IMqttService mqttService;
    @Autowired
    IBluetoochService bluetoochService;
    @Override
    public List<Equipment> list(EquipmentDto dto) {
        EquipmentExample example = new EquipmentExample();
//        example.createCriteria().andUserIdEqualTo(dto.getUserId());
        //TODO 条件不清楚
        List<Equipment> equipmentList = equipmentMapper.selectByExample(example);
        equipmentList.stream().forEach(equipment -> {
            EquipmentFunc equipmentFunc = mqttService.findByEquipId(equipment.getId());
            if (equipmentFunc!=null) {
                EquipmentFunc.parse(equipmentFunc);
                equipment.setEquipmentFunc(equipmentFunc);

            }
            BluetoothVo bluetoothVo = bluetoochService.findByEquitId(equipment.getId());
            equipment.setBluetoothVo(bluetoothVo);
        });
        return equipmentList;
    }

    @Override
    public Equipment getEquipById(Integer equipmentId) {
        return equipmentMapper.selectByPrimaryKey(equipmentId);
    }
}
